home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 October: Mac OS SDK / Dev.CD Oct 96 SDK / Dev.CD Oct 96 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / Draw / Sources / DrwPrmse.cpp < prev    next >
Encoding:
Text File  |  1996-08-16  |  5.1 KB  |  206 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                DrwPrmse.cpp
  4. //    Release Version:    $ ODF 1 $
  5. //
  6. //    Author:                Henri Lamiraux
  7. //
  8. //    Copyright:            (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #include "ODFDraw.hpp"
  13.  
  14. #ifndef DRWPRMSE_H
  15. #include "DrwPrmse.h"
  16. #endif
  17.  
  18. #ifndef DRAWCONT_H
  19. #include "DrawCont.h"
  20. #endif
  21.  
  22. #ifndef BINDING_K
  23. #include "Binding.k"
  24. #endif
  25.  
  26. #ifndef DRAWPRXY_H
  27. #include "DrawPrxy.h"
  28. #endif
  29.  
  30. #ifndef DRAWPART_H
  31. #include "DrawPart.h"
  32. #endif
  33.  
  34. #ifndef DRAWSEL_H
  35. #include "DrawSel.h"
  36. #endif
  37.  
  38. #ifndef BASESHP_H
  39. #include "BaseShp.h"
  40. #endif
  41.  
  42. #ifndef BOUNDSHP_H
  43. #include "BoundShp.h"
  44. #endif
  45.  
  46. #ifndef LINESHP_H
  47. #include "LineShp.h"
  48. #endif
  49.  
  50. #ifndef OVALSHP_H
  51. #include "OvalShp.h"
  52. #endif
  53.  
  54. #ifndef RECTSHP_H
  55. #include "RectShp.h"
  56. #endif
  57.  
  58. #ifndef RRECTSHP_H
  59. #include "RRectShp.h"
  60. #endif
  61.  
  62. #ifndef TEXTSHP_H
  63. #include "TextShp.h"
  64. #endif
  65.  
  66. #ifndef UTILS_H
  67. #include "Utils.h"
  68. #endif
  69.  
  70. // ----- OS Layer -----
  71.  
  72. #ifndef FWSUSINK_H
  73. #include "FWSUSink.h"
  74. #endif
  75.  
  76. #ifndef FWORDCOL_H
  77. #include "FWOrdCol.h"
  78. #endif
  79.  
  80. #ifndef FWPICTUR_H
  81. #include "FWPictur.h"
  82. #endif
  83.  
  84. // ----- Foundation Includes -----
  85.  
  86. #ifndef FWSTREAM_H
  87. #include "FWStream.h"
  88. #endif
  89.  
  90. #ifndef FWPRISTR_H
  91. #include "FWPriStr.h"
  92. #endif
  93.  
  94. #ifndef FWMEMMGR_H
  95. #include "FWMemMgr.h"
  96. #endif
  97.  
  98. #ifndef FWMEMHLP_H
  99. #include "FWMemHlp.h"
  100. #endif
  101.  
  102. // ----- OpenDoc Includes -----
  103.  
  104. #ifndef SOM_Module_OpenDoc_StdProps_defined
  105. #include <StdProps.xh>
  106. #endif
  107.  
  108. #if defined(__MWERKS__) && GENERATING68K
  109. // A hack to work around a bug
  110. #pragma import list somGetGlobalEnvironment
  111. #endif
  112.  
  113. //========================================================================================
  114. // RunTime Info
  115. //========================================================================================
  116.  
  117. #ifdef FW_BUILD_MAC
  118. #pragma segment odfdraw
  119. #endif
  120.  
  121. //========================================================================================
  122. //    class CDrawSelectionPromise
  123. //========================================================================================
  124.  
  125. //----------------------------------------------------------------------------------------
  126. //    CDrawSelectionPromise::CDrawSelectionPromise
  127. //----------------------------------------------------------------------------------------
  128.  
  129. CDrawSelectionPromise::CDrawSelectionPromise(Environment*ev, 
  130.                                             FW_EStorageKinds storageKind, 
  131.                                             FW_CCloneInfo* cloneInfo, 
  132.                                             CDrawPromiseContent* promisedContent) :
  133.     FW_CPromise(ev, storageKind, cloneInfo),
  134.     fPromisedContent(promisedContent)
  135. {
  136.     CDrawContentShapeIterator ite(fPromisedContent);
  137.     for (CBaseShape *shape = ite.First(); ite.IsNotComplete(); shape = ite.Next())
  138.         shape->Promised(storageKind, TRUE);
  139. }
  140.  
  141. //----------------------------------------------------------------------------------------
  142. //    CDrawSelectionPromise::~CDrawSelectionPromise
  143. //----------------------------------------------------------------------------------------
  144.  
  145. CDrawSelectionPromise::~CDrawSelectionPromise()
  146. {
  147.     Environment* ev = somGetGlobalEnvironment();
  148.     CDrawContentShapeIterator ite(fPromisedContent);
  149.     for (CBaseShape *shape = ite.First(); ite.IsNotComplete(); shape = ite.Next())
  150.         shape->Promised(GetStorageKind(ev), FALSE);
  151.  
  152.     delete fPromisedContent;
  153. }
  154.  
  155. //----------------------------------------------------------------------------------------
  156. //    CDrawSelectionPromise::FulfillPromise
  157. //----------------------------------------------------------------------------------------
  158.  
  159. void CDrawSelectionPromise::FulfillPromise(Environment *ev, 
  160.                                             ODStorageUnitView *promiseSUView, 
  161.                                             ODPropertyName propertyName, 
  162.                                             ODValueType valueType, 
  163.                                             FW_CCloneInfo* cloneInfo)
  164. {
  165.     FW_ASSERT(FW_PrimitiveStringEqual(propertyName, kODPropContents));
  166.     if (FW_PrimitiveStringEqual(valueType, kODFDrawKind))
  167.     {
  168.         fPromisedContent->Externalize(ev, promiseSUView->GetStorageUnit(ev), GetStorageKind(ev), cloneInfo);
  169.     }
  170.     else if (FW_PrimitiveStringEqual(valueType, FW_CPart::gMacPICTDataType))
  171.     {
  172.         FW_CPicture picture;
  173.         
  174.         {
  175.             FW_CRect selectionRect = fPromisedContent->GetSelectedRect();
  176.             FW_CPictureContext pc(ev, picture, selectionRect.Width(), selectionRect.Height());
  177.             
  178.             // ----- Clone the contents of the selection -----
  179.             CDrawContentShapeIterator ite(fPromisedContent);
  180.             for (CBaseShape *shape = ite.First(); ite.IsNotComplete(); shape = ite.Next())
  181.             {
  182.                 if (shape->GetShapeType() != kProxyShape)
  183.                 {
  184.                     shape->OffsetShape(ev, -selectionRect.left, -selectionRect.top);
  185.                     shape->RenderShape(ev, NULL, pc);
  186.                     shape->OffsetShape(ev, selectionRect.left, selectionRect.top);
  187.                 }
  188.             }
  189.         }
  190.         
  191.         FW_PlatformPict platformPict = picture.GetPlatformPict();
  192.  
  193.         unsigned long pictSize = FW_CMemoryManager::GetSystemHandleSize((FW_PlatformHandle)platformPict);
  194.     
  195.         FW_CAcquireLockedSystemHandle lockedHandle((FW_PlatformHandle)platformPict);
  196.  
  197.         FW_PStorageUnitSink suSink(ev, promiseSUView);
  198.         FW_CWritableStream stream(suSink);
  199.         stream.Write(lockedHandle.GetPointer(), pictSize);        
  200.     }
  201. #ifdef FW_DEBUG
  202.     else
  203.         FW_DEBUG_MESSAGE("CDrawDesignator::Externalize - Unknown type");
  204. #endif
  205. }
  206.